package www.bplead.com.mydemo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import www.bplead.com.controller.action.scrolldelete.entity.Goods;
import www.bplead.com.mydemo.R;

/**
 * Created by wangyangzi on 2016/9/29.
 */
public class ScrollDeleteAdapter extends BaseAdapter{
    private Context context;
    private List<Goods> goodsList;

    public ScrollDeleteAdapter(Context context, List<Goods> goodsList){
        this.context = context;
        this.goodsList = goodsList;
    }

    @Override
    public int getCount() {
        return goodsList.size();
    }

    @Override
    public Object getItem(int position) {
        return goodsList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Goods goods = (Goods) getItem(position);

        ViewHolder viewHolder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.scroll_delete_item,null);
            viewHolder = new ViewHolder();
            viewHolder.nameTV = (TextView) convertView.findViewById(R.id.scroll_delete_title);
            viewHolder.descriptionTV = (TextView) convertView.findViewById(R.id.scroll_delete_desc);

            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.nameTV.setText(goods.name);
        viewHolder.descriptionTV.setText(goods.description);

        return convertView;
    }

    public static class ViewHolder{
        public TextView nameTV;
        public TextView descriptionTV;
    }
}
